//
//  YQOrderManageBtnActionCell.swift
//  MuYing
//
//  Created by tbb on 2019/8/1.
//  Copyright © 2019 TBB. All rights reserved.
//

import UIKit

@objc protocol YQOrderManageBtnActionCellDelegate:NSObjectProtocol {
    
    func orderSateBtnActionDidSelect(_ indexPath:NSIndexPath,_ currentTitle:NSString);
    func orderSateBtnActionSelected(_ indexPath:NSIndexPath,_ index:Int);
}

class YQOrderManageBtnActionCell: YQTableViewBaseCell {
    @objc var orderModel = YQPOrderEntityModel()

    @objc var refundModel = YQRefundOrderModel()

    @objc var goodsOrdreModel:YQGoodsOrderModel? {
        
        didSet {
            self.rightBtn.isHidden = false;
            self.leftBtn.isHidden = false;
            if self.isAftersale {
                
                switch self.goodsOrdreModel?.orderStatus {
                case 1:
                    self.leftBtn.setTitle(kYQLSSwift("填写物流"), for: .normal)
                    self.rightBtn.setTitle(kYQLSSwift("撤销申请"), for: .normal)
                    break;
                case 2:
                    self.leftBtn.isHidden = true;
                    self.rightBtn.setTitle(kYQLSSwift("撤销申请"), for: .normal)
                    break;
                case 4:
                    self.leftBtn.isHidden = true;
                    self.rightBtn.setTitle(kYQLSSwift("重新申请"), for: .normal)
                    break;
                case 5:
                    break;
                    
                default:
                    break;
                    
                }
                return;
            }
            
//订单列表交互按钮
            switch self.goodsOrdreModel?.orderStatus {
            case 101:
                self.rightBtn.setTitle(kYQLSSwift("立即支付"), for: .normal)
                self.leftBtn.setTitle(kYQLSSwift("取消订单"), for: .normal)
                break
                
            case 102,103,202:
                self.leftBtn.isHidden = true;
                self.rightBtn.setTitle(kYQLSSwift("再次购买"), for: .normal)
                break
            case 201:
                break
            case 301:
                self.leftBtn.setTitle(kYQLSSwift("查看物流"), for: .normal)
                self.rightBtn.setTitle(kYQLSSwift("确认收货"), for: .normal)
                break
            case 302,303:
                self.leftBtn.isHidden = true;
                
                if self.goodsOrdreModel?.comment == "0" {
                    self.rightBtn.setTitle(kYQLSSwift("发布评价"), for: .normal)
                }else{
                    self.rightBtn.setTitle(kYQLSSwift("查看评价"), for: .normal)

                }
                break
            default: break
                
            }
        }
        
    }
    @objc var isAftersale = false;
    @objc var indexPath:NSIndexPath?;
    @objc weak var delegate:YQOrderManageBtnActionCellDelegate?
    @IBOutlet weak var leftBtn: QMUIGhostButton!
    @IBOutlet weak var rightBtn: QMUIGhostButton!
    override func awakeFromNib() {
        super.awakeFromNib()
        self.leftBtn.ghostColor = UIColorFromHex(rgbValue: 0xA0A0A0);
        self.rightBtn.ghostColor = appThemeColor;
        self.leftBtn.tag = 10010;
        self.rightBtn.tag = 10011;
        self.leftBtn.addTarget(self, action: #selector(orderSateBtnAction(_:)), for: .touchUpInside)
        self.rightBtn.addTarget(self, action: #selector(orderSateBtnAction(_:)), for: .touchUpInside)

    }
    
    @objc func orderSateBtnAction(_ sender:QMUIGhostButton) {
        let currenIndex = sender.tag - 10010;
        
        if self.goodsOrdreModel != nil {
            if let delegate = self.delegate, delegate.responds(to: Selector(("orderSateBtnActionSelected::"))),let indexPath = self.indexPath {
                self.delegate?.orderSateBtnActionSelected(indexPath, currenIndex)
            }
        }else{
            if let delegate = self.delegate, delegate.responds(to: Selector(("orderSateBtnActionDidSelect::"))),let indexPath = self.indexPath,let currentTitle = sender.currentTitle{
                self.delegate?.orderSateBtnActionDidSelect(indexPath, currentTitle as NSString);
            }
        }
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    @objc func setRefundOrderModel(_ model:YQRefundOrderModel){
        self.refundModel = model
        self.leftBtn.setTitle(kYQLSSwift("删除订单"), for: .normal)
        self.rightBtn.setTitle(kYQLSSwift("查看详情"), for: .normal)
    }
    
}
